<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    :close-on-click-modal="false"
    width="400px"
    @close="close"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">

      <el-form-item label="物流线路">
        <el-select v-model="form.wuliuCode" placeholder="请选择物流线路" filterable >
          <el-option
            v-for="(item, index) in wuliuList"
            :key="index"
            :value="item.fnumber"
            :label="item.fdataValue"
          ></el-option>
        </el-select>
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { updateOrderWuliu } from '@/api/order'

//修改订单物流信息
export default {
  name: 'EditWuliu',
  data() {
    return {
      //物流
      wuliuList: [],
      form: {
        id: '',
        wuliuName: null,
        wuliuCode:null,
      },
      order:'',
      rules: {
        wuliuName: [
          { required: true, trigger: 'blur', message: '请选择物流线路!' },
        ]
      },
      title: '',
      dialogFormVisible: false,
    }
  },
  created() {
  },
  methods: {
    showEdit(row,wuliuList) {
     this.title = '修改物流线路'
      this.row = row
      this.wuliuList = wuliuList
      this.form.id = row.id
      this.form.wuliuCode = row.wuliuCode
      this.dialogFormVisible = true
    },
    close() {
      this.dialogFormVisible = false
    },
    save() {
      this.form.wuliuName = this.wuliuList.find(o=>o.fnumber==this.form.wuliuCode).fdataValue
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          let msg = ''
          msg = '物流线路修改成功!'
          await updateOrderWuliu(this.form)
          this.$baseMessage(msg, 'success')
          this.row['wuliuCode'] = this.form.wuliuCode
          this.row['wuliuName'] = this.form.wuliuName
          //回更订单详细数据
          this.close()
        } else {
          return false
        }
      })
    },
  },
}
</script>
